package com.jtpay.payresulthelper.service;

import android.content.Intent;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
import com.jtpay.payresulthelper.R;
import com.jtpay.payresulthelper.util.LogUtil;

import static com.jtpay.payresulthelper.util.PayContext.ACTION_ALI_OFFLINE;

/**
 * Description:
 * File: AliNotificationCollectorService.java
 * Author: Administrator
 * Create: 2018/09/26 17:48
 */
public class AliNotificationCollectorService extends NotificationListenerService {
    @Override
    public void onNotificationPosted(StatusBarNotification sbn) {
        String notifyTitle = sbn.getNotification().extras.getString("android.title");
        if (getString(R.string.ali_offline_notify_msg).equals(notifyTitle)) {
            sendBroadcast(new Intent(ACTION_ALI_OFFLINE));
        }
        LogUtil.logOnlySave("onNotificationPosted StatusBarNotification" + "-----" + sbn.toString());
        LogUtil.log("onNotificationPosted"
                + "------ packageName : " + sbn.getPackageName()
                + " |tickerText : " + sbn.getNotification().tickerText
                + " |android.title : " + sbn.getNotification().extras.getString("android.title")
                + " |android.text : " + sbn.getNotification().extras.getString("android.text")
        );
    }

    @Override
    public void onNotificationRemoved(StatusBarNotification sbn) {
        LogUtil.logOnlySave("onNotificationRemoved StatusBarNotification" + "-----" + sbn.toString());
    }
}
